package com.alen.sun.dao;

import com.alen.sun.bean.Content;
import com.alen.sun.bean.Elderly;
import com.alen.sun.bean.Message;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface MessageMapper {

    @Insert("INSERT INTO message(messageId, content, status, elderlyId) VALUES(#{messageId}, #{content}, #{status}, #{elderlyId})")
    void add(Message message);

    @Select("select * from message")
    List<Message> list();

    @Update("update message set status=1 where messageId=#{id}")
    Boolean updateStatus(String id);

    @Select("SELECT m.* FROM message m JOIN elderly e ON m.elderlyId = e.elderlyId WHERE e.employeeId = #{employeeId} AND m.status = 0")
    List<Message> selectMessagesByEmployeeId(@Param("employeeId") String employeeId);

    @Select("select * from message where content like #{word}")
    List<Message> selectByWord(@Param("word") String word);

    @Delete("delete from message where messageId =#{id} AND status = 1")
    Boolean delete(String id);


    //批量删除
    @Delete({
            "<script>",
            "delete from message where messageId in",
            "<foreach item='id' collection='ids' open='(' separator=',' close=')'>#{id}</foreach>",
            "</script>"
    })
    Boolean deleteByIds(List<String> ids);

    @Select("SELECT count(*) FROM message m JOIN elderly e ON m.elderlyId = e.elderlyId WHERE e.employeeId = #{employeeId}")
    Integer getCount(String id);
}
